//
//  LPActivityDetailCommiuncationDetailTableViewCell.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 2017/6/6.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPActivityDetailCommiuncationDetailTableViewCell.h"

@interface LPActivityDetailCommiuncationDetailTableViewCell ()
/**  ren  */
@property (strong, nonatomic) UILabel  *personLabel;
/**  iamgeVEIW  */
@property (strong, nonatomic) UIImageView  *lpImageView;
/**  backImageView  */
@property (strong, nonatomic) UIImageView  *backimageView;
/**  label  */
@property (strong, nonatomic) UILabel  *lpContentLabel;

@end

@implementation LPActivityDetailCommiuncationDetailTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


/**  95 + height  */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}




#pragma mark - 界面
- (void)layoutUI{
    
    [self addSubview:self.lpImageView];
    [self addSubview:self.personLabel];
    [self addSubview:self.backimageView];
    [self.backimageView addSubview:self.lpContentLabel];
    
    
    
}

- (void)setModel:(LPActivityDetailCommiuncationDetailModel *)model{
    _model = model;
    [self layoutUI];
    
    if ([model.SENDER isEqualToString:ZJUSERINFORMODEL.ORG_ACCOUNT.ID]) {
        
        self.lpImageView.sd_layout
        .topSpaceToView(self, 10 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .widthIs(60 * [UIScreen zj_screenHScale])
        .heightIs(60 * [UIScreen zj_screenHScale]);
    
        self.personLabel.textAlignment = NSTextAlignmentRight;
        self.personLabel.sd_layout
        .topSpaceToView(self, 20 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self.lpImageView, 5 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenHScale] - 20 * [UIScreen zj_screenWScale])
        .heightIs(15 * [UIScreen zj_screenHScale]);
        
        self.backimageView.sd_layout.topSpaceToView(self.personLabel, 10 * [UIScreen zj_screenHScale])
        .rightEqualToView(self.personLabel)
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenHScale] - 40 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenHScale] + model.HEIGHT);
        
        self.lpContentLabel.textAlignment = NSTextAlignmentRight;
        self.lpContentLabel.sd_layout.topSpaceToView(self.backimageView, 10 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self.backimageView, 30 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenHScale] - 75 * [UIScreen zj_screenWScale])
        .heightIs(model.HEIGHT);
        

    }else{
        self.lpImageView.sd_layout
        .topSpaceToView(self, 10 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .widthIs(50 * [UIScreen zj_screenHScale])
        .heightIs(50 * [UIScreen zj_screenHScale]);
        
        
        self.personLabel.sd_layout
        .topSpaceToView(self, 20 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.lpImageView, 5 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenHScale] - 20 * [UIScreen zj_screenWScale])
        .heightIs(15 * [UIScreen zj_screenHScale]);
        
        self.backimageView.sd_layout.topSpaceToView(self.personLabel, 10 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.personLabel)
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenHScale] - 40 * [UIScreen zj_screenWScale])
        .heightIs(20 * [UIScreen zj_screenHScale] + model.HEIGHT);
        
        self.lpContentLabel.sd_layout.topSpaceToView(self.backimageView, 10 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.backimageView, 30 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - 60 * [UIScreen zj_screenHScale] - 75 * [UIScreen zj_screenWScale])
        .heightIs(model.HEIGHT);

        
    }
    
    [self.lpImageView sd_setImageWithURL:CREATEURL(model.PHOTO_URL) placeholderImage:PlaceholderImage];
    
    NSString *string = [NSString stringWithFormat:@"%@ %@",model.DATETIME,model.USER_NAME];
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:string];
    [text setAttributes:@{NSForegroundColorAttributeName: [UIColor zj_colorWithR:114 G:207 B:250 Al:1]} range:[string rangeOfString:model.USER_NAME]];
    self.personLabel.attributedText = text;
    
    self.backimageView.backgroundColor = [UIColor lightGrayColor];
    self.lpContentLabel.text = model.MSGCONTENT;
    
}

- (void)setIsNoData:(BOOL)isNoData{
    _isNoData = isNoData;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 60 * [UIScreen zj_screenHScale])];
    label.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
    label.textColor = [UIColor textBlackColor];
    label.text = @"暂无交流";
    label.backgroundColor = [UIColor themeGrayColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
}


#pragma mark - getter
- (UILabel *)lpContentLabel{
    if (!_lpContentLabel) {
        _lpContentLabel = ({
            UILabel *label = [UILabel new];
            label.numberOfLines = 0;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:17 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _lpContentLabel;
}



- (UILabel *)personLabel{
    if (!_personLabel) {
        _personLabel = ({
            UILabel *label = [UILabel new];
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:16 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _personLabel;
}
- (UIImageView *)lpImageView{
    if (!_lpImageView) {
        _lpImageView = [UIImageView new];
        _lpImageView.layer.cornerRadius = 25 * [UIScreen zj_screenHScale];
        _lpImageView.layer.masksToBounds = YES;
    }
    return _lpImageView;
}
- (UIImageView *)backimageView{
    if (!_backimageView) {
        _backimageView = [UIImageView new];
    }
    return _backimageView;
}

@end
